<?php
namespace Model;
use Think\Model;
class ManagerModel extends Model {
	protected $patchValidate = true;
	
	protected $_validate = array(
			array('name','require','账号必须填写'),
			array('name','','帐号名称已经存在！',0,'unique',1), 
  			array('repassword','password','确认密码不正确',0,'confirm'),
			array('number','11','电话号码不合法',0,'length'),
			array('password','5,11','密码长度不合法','0','length'),
	);
	
	function get_client_ip() {
		if(getenv('HTTP_CLIENT_IP')){
			$client_ip = getenv('HTTP_CLIENT_IP');
		} elseif(getenv('HTTP_X_FORWARDED_FOR')) {
			$client_ip = getenv('HTTP_X_FORWARDED_FOR');
		} elseif(getenv('REMOTE_ADDR')) {
			$client_ip = getenv('REMOTE_ADDR');
		} else {
			$client_ip = $_SERVER['REMOTE_ADDR'];
		}
		return $client_ip;
	}
	
	function savemanager($post) {
		$post['add_time'] = $post['last_time'] = strtotime(date('Y-m-d H:i:s'));
		$post['ip'] = $this->get_client_ip();
		$post['password'] = md5($post['password']);
		unset($post['repassword']);
		return $post;
	}
}